﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Entitys;
namespace KCMS.DataAcsess.Engine
{
    public class ProductCategoryManager:IProductCategoryManager
    {
        protected DataClassesDataContext db = new DataBaseConnect().DataBase;
        private DataManager<ProductCategoryEntity> dm = new DataManager<ProductCategoryEntity>();
        public ProductCategoryEntity getById(Guid id)
        {
            return (from t in db.GetTable<ProductCategoryEntity>()
                    where t.Id.Equals(id)
                    select t).SingleOrDefault();
        }
        public IEnumerable<ProductCategoryEntity> getAll()
        {
            //return (from t in db.GetTable<ProductCategoryEntity>()
            //            select t).ToList();
            return dm.getAll();
        }

        public void delete(Guid id)
        {
            //var model = getById(id);
            //db.GetTable<ProductCategoryEntity>().DeleteOnSubmit(model);
            //db.SubmitChanges();
            dm.delete(id);
        }

        public void update(ProductCategoryEntity productCategory)
        {
            db = new DataBaseConnect().DataBase;
            var old = getById(productCategory.Id);
            old.CopyPropyties(productCategory);
            db.SubmitChanges();
        }

        public void save(ProductCategoryEntity productCategory)
        {
            //var model = getById(id);
            //db.GetTable<ProductCategoryEntity>().InsertOnSubmit(model);
            //db.SubmitChanges();
            dm.save(productCategory);
        }
    }
}
